<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>PotatoCMS</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="__ADMIN__/bootstrap/css/bootstrap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="__ADMIN__/adminlte/css/AdminLTE.min.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <style>
    body{
      background: url('__ADMIN__/images/bg.jpg')  top center no-repeat;
      background-size: 100% 100%;
      overflow: hidden;
    }
  </style>
</head>
<body>
<div class="login-box">
  <div class="login-logo">
    <a href=""><b>Potato</b>CMS</a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
    <p class="login-box-msg">后台登录入口</p>

    <form action="" method="post" id="myForm" onsubmit='return goLogin()'>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" id="username" name="username" placeholder="用户名">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" class="form-control" id="password" name="password" placeholder="密码">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group" style="overflow: hidden;">
          <input type="text" name="captcha" style="line-height: 30px; border-color:#d2d6de;border-style: solid;outline:none;border-width:1px;"  placeholder="验证码">
          <img src="{:captcha_src()}" id="captcha" class="verify" onclick="javascript:this.src='{:captcha_src()}?rand='+Math.random()" >
      </div>

      <div class="form-group">
          <div class="checkbox">
            <label>
              <input type="checkbox" id="remember"> 记住密码
            </label>
        </div>
      </div>
      <div class="form-group has-feedback">
        <button type="submit" id="btn"  class="btn btn-primary btn-block btn-flat">登录</button>
      </div>
    </form>


  </div>
  <!-- /.login-box-body -->
</div>

</body>
<script>
    function captcha() {
        var captcha = document.getElementById('captcha');
        captcha.src = '{:captcha_src()}?' + 'rand=' + Math.random();
    }
    var oForm = document.getElementById('myForm');
    var oUser = document.getElementById('username');
    var oPswd = document.getElementById('password');
    var oRemember = document.getElementById('remember');
    //页面初始化时，如果帐号密码cookie存在则填充
    if (getCookie('username') && getCookie('password')) {
        oUser.value = getCookie('username');
        oPswd.value = getCookie('password');
        oRemember.checked = true;
    }
    //复选框勾选状态发生改变时，如果未勾选则清除cookie
    oRemember.onchange = function() {
        if (!this.checked) {
            delCookie('username');
            delCookie('password');
        }
    };
    //表单提交事件触发时，如果复选框是勾选状态则保存cookie
    function goLogin(){
        if (remember.checked) {
            setCookie('username', oUser.value, 7); //保存帐号到cookie，有效期7天
            setCookie('password', oPswd.value, 7); //保存密码到cookie，有效期7天
        }
        return true;
    };
    window.onload=function(){
        captcha();


    };
    //设置cookie
    function setCookie(name, value, day) {
        var date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = name + '=' + value + ';expires=' + date;
    };
    //获取cookie
    function getCookie(name) {
        var reg = RegExp(name + '=([^;]+)');
        var arr = document.cookie.match(reg);
        if (arr) {
            return arr[1];
        } else {
            return '';
        }
    };
    //删除cookie
    function delCookie(name) {
        setCookie(name, null, -1);
    };

</script>
</html>
